home *** CD-ROM | disk | FTP | other *** search
- Path: erich.triumf.ca!bennett
- From: bennett@erich.triumf.ca (P.Bennett)
- Newsgroups: comp.lang.c
- Subject: Re: HELP! File Pointers
- Date: 9 Jan 1996 07:37 PST
- Organization: TRIUMF: Tri-University Meson Facility
- Distribution: world
- Message-ID: <9JAN199607374098@erich.triumf.ca>
- References: <4csr4c$fem@newsbf02.news.aol.com>
- NNTP-Posting-Host: ftp.triumf.ca
- News-Software: VAX/VMS VNEWS 1.50
-
- In article <4csr4c$fem@newsbf02.news.aol.com>, roberino@aol.com (Roberino) writes...
- >I am currently trying to keep one file open while opening other
- >files one at a time using a separate file pointer. However, as
- >soon as I read a line from the second file, the first file pointer
- >somehow gets destroyed and set to some position in the newly
- >opened file. Has anyone else encountered this? And if so,
- >is there a solution? (i.e. A way to protect the first file pointer
- >from being overwritten.)
- >
- >Here are the steps I am performing:
- >
- >void main()
-
- According to the ANSI/ISO C standard, main() _must_ return an int (despite many
- books to the contrary). Then you need a "return 0;" at the end of main().
- (However, void main() rarely causes any problems...)
-
- >{
- > FILE *File1;
- > FILE *File2;
- >
- > File1 = fopen("FILENAME", "r+");
- >
- > /* loop through lines in File1 using fgets() */
- >
- > if (Condition) /* just indicating some condition was met */
- > {
- > File2 = fopen("FILENAME2", "r+");
- >
- > fgets(Line, File2); <----- As soon as this occurs, File1 gets
- > wiped out. Why?
-
- In my books, fgets() takes 3 parameters: buffer, size, stream - so this should
- be perhaps fgets(Line, sizeof(LINE), File2);
-
- How is Line declared? It should be declared as a char array large enough to
- hold the input line.
-
- Peter Bennett VE7CEI | Vessels shall be deemed to be in sight
- Internet: bennett@triumf.ca | of one another only when one can be
- Packet: ve7cei@ve7kit.#vanc.bc.ca | observed visually from the other
- TRIUMF, Vancouver, B.C., Canada | ColRegs 3(k)
- GPS and NMEA info and programs: ftp://sundae.triumf.ca/pub/peter/index.html
-
-
-
-
-
-
-
-